<!DOCTYPE HTML>
<style>

body {
  height: 30000px;
  width: 30000px;
}

.spacer {
  height: 1000px;
  width: 1000px;
}

#scroller {
  height: 100px;
  width: 100px;
  overflow: scroll;
}
</style>

<div id=scroller>
    <div class=spacer></div>
</div>

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
function scrollToNonFinite(x, y) {
  window.scrollTo(100, 100);
  window.scrollTo(x, y);
  assert_equals(window.scrollY, 0);
  assert_equals(window.scrollX, 0);

  window.scrollTo(100, 100);
  window.scrollTo({top: y, left: x});
  assert_equals(window.scrollY, 0);
  assert_equals(window.scrollX, 0);
}

function scrollByNonFinite(x, y) {
  window.scrollTo(100, 100);
  window.scrollBy(x, y);
  assert_equals(window.scrollY, 100);
  assert_equals(window.scrollX, 100);

  window.scrollTo(100, 100);
  window.scrollBy({top: y, left: x});
  assert_equals(window.scrollY, 100);
  assert_equals(window.scrollX, 100);
}

function scrollTopNonFinite(y) {
  scroller.scrollTop = 1;
  assert_equals(scroller.scrollTop, 1);
  scroller.scrollTop = y;
  assert_equals(scroller.scrollTop, 0);
}

function scrollLeftNonFinite(x) {
  scroller.scrollLeft = 1;
  assert_equals(scroller.scrollLeft, 1);
  scroller.scrollLeft = x;
  assert_equals(scroller.scrollLeft, 0);
}

test(()=> {
  window.scrollTo(1, 1);
  assert_equals(window.scrollY, 1);
  assert_equals(window.scrollX, 1);

  scrollToNonFinite(window.NaN, window.NaN);
  scrollToNonFinite(window.Infinity, window.Infinity);
  scrollToNonFinite(0, window.Infinity);
  scrollToNonFinite(-window.Infinity, -window.Infinity);

  scrollByNonFinite(window.NaN, window.NaN);
  scrollByNonFinite(window.Infinity, window.Infinity);
  scrollByNonFinite(0, window.Infinity);
  scrollByNonFinite(-window.Infinity, -window.Infinity);

  scrollTopNonFinite(window.NaN);
  scrollTopNonFinite(window.Infinity);
  scrollTopNonFinite(-window.Infinity);

  scrollLeftNonFinite(window.NaN);
  scrollLeftNonFinite(window.Infinity);
  scrollLeftNonFinite(-window.Infinity);
}, "Verifies that nan scroll position works correctly.");

</script>
